name: Symfony-PhpStan

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

permissions:
  contents: read

jobs:
  symfony-phpstan:
    runs-on: ubuntu-latest
    steps:
    - uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28
      with:
        php-version: '8.3'
    - uses: actions/checkout@v3
    - name: Copy .env.test.local
      run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"
    - name: Cache Composer packages
      id: composer-cache
      uses: actions/cache@v3
      with:
        path: vendor
        key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
        restore-keys: |
          ${{ runner.os }}-php-
    - name: Install Dependencies
      run: composer install
    - name: PHPStan
      run: vendor/bin/phpstan

  symfony-pint:
    runs-on: ubuntu-latest
    steps:
      - uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28
        with:
          php-version: '8.3'
      - uses: actions/checkout@v3
      - name: Copy .env.test.local
        run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"
      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v3
        with:
          path: vendor
          key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-php-
      - name: Install Dependencies
        run: composer install
      - name: Pint
        run: vendor/bin/pint --test

  symfony-test:
    runs-on: ubuntu-latest
    services:
      mysql-service:
        image: mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: example
          MYSQL_DATABASE: db_test
        ports:
          - 33306:3306
        options: >-
          --health-cmd="mysqladmin ping"
          --health-interval=10s
          --health-timeout=5s
          --health-retries=3
    steps:
      - uses: actions/checkout@v2
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
      - name: Install dependencies
        run: composer install --no-scripts
      - name: Fill Db
        run: php bin/console doctrine:schema:create --env=github
      - name: Copy .env
        run: php -r "file_exists('.env.test.local') || copy('.env.github.test', '.env.test.local');"
      - name: Run test
        run: ./vendor/bin/phpunit
